<template>
    <div>
        <h1>房号修改</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td><input type="text" v-model="info.roomname" /></td>
                </tr>
                <tr>
                    <td>房号</td>
                    <td><input type="text" v-model="info.roomhao" /></td>
                </tr>
                <tr>
                    <td>排序</td>
                    <td><input type="text" v-model="info.pai" /></td>
                </tr>
                <tr>
                    <td>备注</td>
                    <td>
                        <textarea v-model="info.beizhu" role="50" sort="5"></textarea>
                    </td>
                </tr>
                <tr>
                    <td>创建时间</td>
                    <td><input type="date" v-model="info.createTime" /></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" v-model="info.state" name="state" value="1" />上架
                        <input type="radio" v-model="info.state" name="state" value="0" />下架
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button"  class="btn btn-success" value="修改" @click="ok"/></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { onMounted,reactive,ref } from 'vue';
import { useRoute,useRouter } from 'vue-router';
import axios from 'axios';

const route=useRoute();
const router=useRouter();


let info=reactive({
    id:route.query.xid,
    roomname:'',
    roomhao:'',
    pai:'',
    beizhu:'',
    createTime:'',
    state:1
})

//钩子函数
onMounted (()=>{
    FanTian();
})
//反填
const FanTian=()=>{
    axios({
        url:'/api/RoomH/FanTian',
        method:'get',
        data:{
            id:route.query.xid
        }
    })
    .then(res=>{
        console.log(res);
        info.roomname=res.data.roomname;
        info.roomhao=res.data.roomhao;
        info.pai=res.data.pai;
        info.beizhu=res.data.beizhu;
        info.createTime=res.data.createTime;
        info.state=res.data.state;
    })
}


const ok=()=>{
    axios({
        url:'/api/RoomH/Update',
        method:'put',
        data:info
    })
    .then(res=>{
        console.log(res);
        if(res.data>0){
            alert('修改成功!');
            router.push('/RoomHList');
        }
        else{
            alert('修改失败!');
        }
    })
}


</script>
